# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +---------------------------------------------------------------------
from common.utils.config import ConfigUtil
from apps.admin.schemas.apply.music import setting_schema as schema


class MusicSettingService:

    @classmethod
    async def detail(cls) -> schema.MusicSettingIO:
        """
        音乐配置详情

        Returns:
            schema.MusicSettingIO

        Author:
            zero
        """
        suno = await ConfigUtil.get("music", "suno") or {}
        return schema.MusicSettingIO(
            suno=schema.MusicConfig(
                status=int(suno.get("status", 0)),
                points=int(suno.get("points", 0)),
                channel=str(suno.get("channel", "")),
                name=str(suno.get("name", "")),
            )
        )

    @classmethod
    async def save(cls, post: schema.MusicSettingIO) -> None:
        """
        音乐配置保存

        Args:
            post (schema.MusicSettingIO): 配置参数

        Author:
            zero
        """
        await ConfigUtil.set("music", "suno", {
            "status": int(post.suno.status),
            "points": int(post.suno.points),
            "channel": str(post.suno.channel),
            "name": str(post.suno.name)
        })
